import 'package:flutter/material.dart';
import 'package:qunaimedical/components/custom_divider.dart';
import 'package:qunaimedical/components/primary_label.dart';
import 'package:qunaimedical/components/rounded_network_image.dart';
import 'package:qunaimedical/models/check_item.dart';
import 'package:qunaimedical/utils/common_util.dart';
import 'package:qunaimedical/values/urls.dart';

/// 检查报告详情
class CheckItemDetail extends StatefulWidget {
  final CheckItem item;

  const CheckItemDetail(this.item, {Key key}) : super(key: key);

  @override
  _CheckItemDetailState createState() => _CheckItemDetailState();
}

class _CheckItemDetailState extends State<CheckItemDetail> {
  @override
  Widget build(BuildContext context) {
    var _images =
        widget.item.enclosure == '' ? [] : widget.item.enclosure.split(',');
    var paddingValue = EdgeInsets.only(left: 16, right: 16, bottom: 16);
    return Scaffold(
      appBar: AppBar(
        title: Text('详情'),
      ),
      body: ListView(
        padding: EdgeInsets.only(top: 10),
        children: [
          PrimaryLabel('报告信息'),
          Container(
            padding: paddingValue,
            child: Text('报告名称：${widget.item.checkName}'),
            color: Colors.white,
          ),
          Container(
            padding: paddingValue,
            child: Text('检测时间：${widget.item.checkTime}'),
            color: Colors.white,
          ),
          CustomDivider(),
          PrimaryLabel('报告图片'),
          Container(
            color: Colors.white,
            height: 90,
            width: double.maxFinite,
            alignment: Alignment.topLeft,
            padding: paddingValue,
            child: ListView.separated(
              scrollDirection: Axis.horizontal,
              itemBuilder: (c, i) {
                return InkWell(
                  onTap: () => CommonUtils.openGallery(context,
                      _images.map((e) => Urls.BASE_URL + e).toList(), i),
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(6)),
                    child:  RoundedNetWorkImage('${Urls.BASE_URL}${_images[i]}'),
                  ),
                );
              },
              itemCount: _images.length,
              separatorBuilder: (BuildContext context, int index) {
                return SizedBox(width: 10);
              },
            ),
          )
        ],
      ),
    );
  }
}
